<style scoped>
.layout {
    border: 1px solid #d7dde4;
    background: white;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
}

.layout-logo {
    width: 100px;
    height: 30px;
    background: #5b6270;
    border-radius: 3px;
    float: left;
    position: relative;
    top: 15px;
    left: 20px;
}

.layout-nav {
    width: 320px;
    margin: 0 auto;
    margin-right: 20px;
    background: white;
}
</style>
<template>
<div>
    <Card>

        <Input v-model="addnormalname" placeholder="输入新建的模式名称" style="width: 200px" />
         &nbsp;
        <Input v-model="addnormaldesc" placeholder="输入新建的模式描述" style="width: 200px" />
         &nbsp;
        <Button type="primary" @click="addnormal"  >增加</Button>
    </Card>
    <br/>
    <Card>
        <Table :columns="normal_header" :data="normal_data"></Table>
    </Card>

</div>
</template>

<script>
export default {
    name: 'HelloWorld',
    props: {
        msg: String
    },
    methods: {
        addnormal() {
            var normalname = this.addnormalname
            var addnormaldesc = this.addnormaldesc
            this.addnormalname = ''
            this.addnormaldesc = ''
            var that=this;
            if (normalname == null || normalname == '') {
                alert("请输入模式名称")
            }
            if (addnormaldesc == null || addnormaldesc == '') {
                alert("请输入模式描述")
            }
            const axios1 = require('axios')
            var pd = {
                name: normalname,
                desc: addnormaldesc
            }
            axios1.post('/ins_normal_flow', pd).then(function (req) {
                var data = req.data
                if (data.Code != 0) {
                    alert(data.desc)
                }
                that.refresh_normal_data()

            }).catch(function (e) {
                console.log(e)
            })
            
        },
        refresh_normal_data() {
            var that = this
            const a1 = require('axios')
            a1.post('get_normal_flow', {
                id: -1
            }).then(function (req) {
                var data = req.data

                if (data.Code == 0) {
                    that.normal_data = []
                    for (var i in data.data) {
                        var d = data.data[i]

                        var t = {}
                        t.id = d.ID
                        t.name = d.Name
                        t.desc = d.Desc
                        that.normal_data.push(t)
                    }
                }

            }).catch(function (e) {})
        }

    },
    created() {
        this.normal_header = [{
                title: 'id',
                key: 'id'
            },
            {
                title: '名称',
                key: 'name'
            },
            {
                title: '描述',
                key: 'desc'
            }
        ];
        this.normal_data = []
        this.refresh_normal_data()
    },
    computed: {

    },
    data() {
        return {
            addnormalname: null,
            Content: null,
            normal_header: null,
            normal_data: null,
            addnormaldesc: null

        }
    }
}
</script>
